home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Ian & Stuart's Australian Mac 1993 September
/
clonecd
/
September 93.img
/
Archives
/
Utilities
/
Security - care
/
Protect
/
Tonto
/
tonto.c
< prev
next >
Wrap
C/C++ Source or Header
|
1991-11-26
|
9KB
|
410 lines
/*
Application management program
Copyright 1988 Greg Coleman, Purdue University
Extensive modifications by Dale Talcott
Purdue University Computing Center
These sources may be freely distributed provided this notice remains
intact.
*/
//# include <Dialogs.h>
//# include <Events.h>
//# include <Menus.h>
//# include <Files.h>
//# include <StdFilePkg.h>
# include "Tonto.h"
/*
* Define new launch param structure
*/
typedef struct {
StringPtr pfName;
Integer param;
char LC[2];
Longint extBlockLen;
Integer fFlags;
Longint launchFlags;
} LaunchStruct;
/*
* Prototypes for local functions
*/
void CmdMode (void);
void main (void);
void myLaunch (LaunchStruct *);
pascal void Res (void);
void RunMode (void);
void SkelInit (void);
/*
* Globals
*/
Integer myRefNum;
Integer myVolRef;
Handle myParam;
Str255 myName;
Str255 myVolume;
void
main()
{
OSErr result;
HParamBlockRec pb;
FCBPBRec fc;
Str255 lx;
SkelInit ();
/*
* Determine the name and refnum of the volume containing ourselves
*/
GetAppParms (myName, &myRefNum, &myParam);
ZERO (fc);
fc.ioNamePtr = lx;
lx[0] = 0;
fc.ioRefNum = myRefNum;
result = PBGetFCBInfo (&fc, FALSE);
if (result)
OSError ((SP)"\pCan't find ourselves", result, myName);
ZERO (pb);
pb.volumeParam.ioVRefNum = fc.ioFCBVRefNum;
pb.volumeParam.ioNamePtr = myVolume;
myVolume[0] = 0;
result = PBHGetVInfo (&pb, FALSE);
if (result)
OSError ((SP)"\pCan't get vol info", result, myVolume);
myVolRef = pb.volumeParam.ioVRefNum;
/*
* If the settings haven't been made permanent and the button
* is down, go into command mode.
* Otherwise, run the configured application.
*/
if ( (GetNamedStr("\pperm", lx) == 0) && Button() )
CmdMode();
else
RunMode();
ExitToShell();
}
void
CmdMode()
{
DialogPtr dialog;
DialogPtr aboutdialog, permdialog;
OSErr result;
Integer item;
char *ts;
int i;
char tmp[5];
Integer type;
Handle theItem;
Str255 sline;
StringPtr line = &sline[0];
Rect box;
SFTypeList msflist;
Point mpt;
SFReply myreply;
FInfo myinfo;
Str255 path;
Integer vRefNum;
Boolean changed = false;
HParamBlockRec pb;
FCBPBRec fc;
CInfoPBRec ci;
CInfoPBRec myci;
/*
* Remember who and where we are
*/
ZERO (fc);
fc.ioNamePtr = line;
line[0] = 0;
fc.ioRefNum = myRefNum;
result = PBGetFCBInfo (&fc, FALSE);
ZERO (myci);
myci.hFileInfo.ioNamePtr = myName;
myci.hFileInfo.ioVRefNum = fc.ioFCBVRefNum;
myci.hFileInfo.ioDirID = fc.ioFCBParID;
result = PBGetCatInfo (&myci, FALSE);
/*
* Put up and fill in our main dialog
*/
dialog = GetNewDialog(MAIN_DIALOG, (DialogPeek)0L, (WindowPtr)-1L);
GetNamedStr("\papname", line);
SetText(dialog,APNAME,line);
GetNamedStr("\pcreator", line);
SetText(dialog,CREATOR,line);
GetNamedStr("\ppath", line);
SetText(dialog,PATH,line);
ShowWindow (dialog);
/*
* Handle user actions
*/
while(1)
{
ModalDialog(0L, &item);
switch(item)
{
case DONE:
if (changed == false)
return;
/*
* Get info about the application
*/
ZERO (ci);
ci.hFileInfo.ioNamePtr = myreply.fName;
ci.hFileInfo.ioVRefNum = myreply.vRefNum;
result = PBGetCatInfo (&ci, FALSE);
if (result)
OSError ((SP)"\pCan't get info about application ", result,
(SP)myreply.vRefNum);
/*
* Change our Finder creator info to match that
* of the application we are subbing for.
* (The test on the next line avoids changing it
* if our name ends in pi. This is to keep from
* changing the creator of the project file when running
* under the LightSpeed debugger.)
*/
if (myName[myName[0]] != ('π' & 0xff)) {
myci.hFileInfo.ioFlFndrInfo.fdCreator =
ci.hFileInfo.ioFlFndrInfo.fdCreator;
myci.hFileInfo.ioFlFndrInfo.fdFlags &= ~fHasBundle;
myci.hFileInfo.ioFDirIndex = 0;
myci.hFileInfo.ioDirID = fc.ioFCBParID;
result = PBSetCatInfo (&myci, FALSE);
if (result)
OSError ((SP)"\pCan't change our Finder info",
result, (SP)"");
}
/*
* Save away configuration strings from dialog settings
*/
GetDItem (dialog, APNAME, &type, &theItem, &box);
GetIText (theItem, line);
SetNameStr ("\papname", line);
GetDItem (dialog, CREATOR, &type, &theItem, &box);
GetIText (theItem, line);
SetNameStr ("\pcreator", line);
GetDItem (dialog, PATH, &type, &theItem, &box);
GetIText (theItem, line);
SetNameStr ("\ppath", line);
return;
case ABOUT:
aboutdialog = GetNewDialog(ABOUT_DIALOG,
(DialogPeek)0L, (WindowPtr)-1L);
ShowWindow (aboutdialog);
ModalDialog(0L, &item);
DisposDialog(aboutdialog);
break;
case PERM:
permdialog = GetNewDialog(PERM_DIALOG,
(DialogPeek)0L, (WindowPtr)-1L);
ShowWindow (permdialog);
ModalDialog(0L, &item);
if (item == 1)
{
DisposDialog(permdialog);
continue;
}
SetNameStr("\pperm",(SP)"\pgreggc");
return;
case BUILD:
/*
* Have the user locate the application to run
*/
msflist[0] = 'APPL';
msflist[1] = '????';
SetPt(&mpt, 100, 100);
SFGetFile(mpt, (SP)NULL, (FileFilterProcPtr)NULL, 2,
msflist, (ProcPtr)NULL, &myreply);
if (myreply.good == false)
break;
/*
* Put information about the application into the
* dialog.
* The trickiest part is setting the path to use to
* locate the appl later. If the appl is on the same
* volume as we are, we delete the leading volume name
* from the path. If it is on a different volume, we
* keep the whole path.
* This allows identical, configured copies of Tonto
* to be used on lab Macs, where all the local hard
* disks are essentially the same, except that each
* Mac's disk has a unique name.
*/
ZERO(ci);
ci.hFileInfo.ioNamePtr = myreply.fName;
ci.hFileInfo.ioVRefNum = myreply.vRefNum;
result = PBGetCatInfo (&ci, FALSE);
if (result)
OSError ((SP)"\pCan't get app info", result, myreply.fName);
ts = (char *)&ci.hFileInfo.ioFlFndrInfo.fdCreator;
for (i = 0; i < 4; i++)
tmp[i+1] = ts[i];
tmp[0] = i;
pstrcpy (path, myreply.fName);
pathname (path, myreply.vRefNum, sizeof (path)-1);
if (path[0] != 0) {
ZERO(pb);
pb.volumeParam.ioVRefNum = myreply.vRefNum;
pb.volumeParam.ioNamePtr = line;
line[0] = 0;
result = PBHGetVInfo(&pb, FALSE);
if (result)
OSError((SP)"\pCan't get vol info", result, line);
if (pb.volumeParam.ioVRefNum == myVolRef) {
i = line[0];
pstrcpy (line, path);
line[i] = path[0] - i;
pstrcpy (path, line + i);
if (path[0] == 0) { /* if appl at top level */
path[1] = ':';
path[0] = 1;
}
}
GetDItem(dialog, CREATOR, &type, &theItem, &box);
SetIText(theItem,(SP)tmp);
GetDItem(dialog, APNAME, &type, &theItem, &box);
SetIText(theItem,myreply.fName);
GetDItem(dialog, PATH, &type, &theItem, &box);
SetIText(theItem, path);
changed = true;
}
break;
}
}
}
void
RunMode()
{
OSErr result;
Integer item; /* dialog result */
Str255 line; /* temp */
Str255 path; /* partial path name */
DialogPtr errdialog;
WDPBRec wd;
CInfoPBRec ci; /* file catalog info */
LaunchStruct ls; /* launch params */
/*
* Fetch the saved path.
* If it begins with ':', prepend the volume name we are from.
*/
while (1) { /* dummy loop */
GetNamedStr ("\ppath", path);
if (path[0] == 0) {
result = 0;
break;
}
if (path[1] == ':') {
pstrcpy(line, path);
if (path[0] + myVolume[0] >= sizeof (path))
break;
pstrcat2(path, myVolume, line);
}
ZERO (wd);
wd.ioNamePtr = path;
wd.ioWDProcID = 'ERIK';
result = PBOpenWD (&wd, FALSE);
if (result)
break;
result = SetVol ((SP)NULL, wd.ioVRefNum);
if (result)
break;
GetNamedStr ("\papname", path);
if (path[0] == 0)
break;
ZERO (ci);
ci.hFileInfo.ioNamePtr = path;
ci.hFileInfo.ioVRefNum = wd.ioVRefNum;
result = PBGetCatInfo (&ci, FALSE);
if (result == noErr) {
ZERO (ls);
ls.pfName = path;
ls.LC[0] = 'L'; ls.LC[1] = 'C';
ls.extBlockLen = 6;
ls.fFlags = ci.hFileInfo.ioFlFndrInfo.fdFlags;
myLaunch (&ls);
/*NOTREACHED*/
}
break;
}
if (result) {
NumToString ((long)result, line);
item = FakeAlert ((SP)"\pCannot find application \"", path,
(SP)"\p\" error = ", line, 2, 1,
(SP)"\pQuit", (SP)"\pConfigure", (SP)"\p");
if (item == 2)
result = 0;
}
if (result == 0)
CmdMode();
}
void
myLaunch (ls)
register LaunchStruct *ls;
{
asm {
movea.l ls,a0
_Launch
_ExitToShell
}
/*NOTREACHED*/
}
pascal void
Res ()
{
ExitToShell();
/*NOTREACHED*/
}
void
SkelInit ()
{
MaxApplZone ();
InitGraf ((Ptr) &thePort);
InitFonts ();
InitWindows ();
InitMenus ();
TEInit ();
InitDialogs (Res);
InitCursor ();
}